package xin.handler;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import xin.entity.CommonResult;
@RestControllerAdvice
public class HandlerException {

    @ExceptionHandler(value = Exception.class)
    public CommonResult<?> handlerException(Exception e){
        e.printStackTrace();
        CommonResult commonResult = new CommonResult();
        if (e instanceof MyException){
            MyException industryException = (MyException) e;
            commonResult.setData(null);
            commonResult.setCode(industryException.getCode());
            commonResult.setMsg(industryException.getMsg());
        }
        else {
            commonResult.setData(null);
            commonResult.setCode(500);
            commonResult.setMsg("内部服务器未知异常");
        }
        return commonResult;
    }
}
